﻿using System.Web.UI;
using SPFluid.ServiceLocation;
using SPFluid.UI.Presenters;
using SPFluid.UI.Views;

namespace SPFluid.UI.Controls
{
    public abstract class UserControlBase<TPresenter, TView> : UserControl, IView
        where TPresenter : PresenterBase<TView>
        where TView : class, IView
    {
        private TPresenter presenter;

        public TPresenter Presenter
        {
            get
            {
                if (this.presenter == null)
                {
                    var serviceLocator = FluidServiceLocator.GetCurrent();

                    this.presenter = serviceLocator.GetInstance<TPresenter>();
                    this.presenter.View = this as TView;
                }

                return this.presenter;
            }
        }
    }
}